/*
*	Copyright (C) 2008-2009  Devioux.com
*
*    This program is free software: you can redistribute it and/or modify
*    it under the terms of the GNU General Public License as published by
*    the Free Software Foundation, either version 3 of the License, or
*    (at your option) any later version.
*
*    This program is distributed in the hope that it will be useful,
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*    GNU General Public License for more details.
*
*    You should have received a copy of the GNU General Public License
*    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
package com.devioux.inter;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class VarChecker {

	private static final String[] order = {"String", "Integer", "Boolean"};
	private String name;
	
	public VarChecker(String name) {
		this.name = name;
	}
	
	public boolean checkExsist() throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, ClassNotFoundException, InstantiationException, SecurityException, NoSuchMethodException {		
		for (int i = 0; i < order.length; i++) {
			Class<?> cls  = Class.forName("com.devioux.inter.lang." + order[i]);
			Object   obj  = cls.newInstance();
			Method   meth = cls.getMethod("getValue", new Class[]{String.class});
			
			if (meth.invoke(obj, new Object[]{name}) != null)
				return true;
		}
		
		return false;
	}
	
	public String check() throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, ClassNotFoundException, InstantiationException, SecurityException, NoSuchMethodException {		
		for (int i = 0; i < order.length; i++) {			
			Class<?> cls  = Class.forName("com.devioux.inter.lang." + order[i]);
			Object   obj  = cls.newInstance();
			Method   meth = cls.getMethod("getValue", new Class[]{String.class});
			
			if (meth.invoke(obj, new Object[]{name}) != null)
				return order[i];
		}
		
		return null;
	}
}
